package games.ninJumpDx.ui.actions
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.utils.getTimer;
	
	import games.ninJumpDx.data.GameData;
	import games.ninJumpDx.data.UIConfig;
	import games.ninJumpDx.tools.Tools;
	
	import utils.Cartoon;
	
	public class Wall extends Cartoon
	{
		private var m_bmd:BitmapData;
		private var m_walls:Vector.<Bitmap>;
		private var m_bm:Bitmap;
		
		public function Wall()
		{
			super();
			init();
		}
		
		override public function update(t:Object=null):void
		{
			if(!start || pause)return;
			//var time:Number = getTimer() - m_startTime;
			m_walls.sort(sortByY);
		
			for(var i:int = 0; i < m_walls.length; i++)
			{
				if(m_walls[i].y >= UIConfig.getGameHeight())
					m_walls[i].y = m_walls[0].y - m_walls[i].height;
				m_walls[i].y += GameData.instance.speed ; 
				//m_walls[i].y = (m_walls[i].height * i + time * GameData.instance.speed ) % (UIConfig.getGameHeight() + m_walls[i].height) -  m_walls[i].height;
			}
			//trace("m_walls[0].y:	",m_bm.y);
		}
		
		private function init():void
		{
			m_bmd = Tools.getBitmapDataByName("wall",GFrame.MAIN_UI);
			m_walls = new Vector.<Bitmap>();
			for(var i:int = 0; i < 10; i++)
			{
				m_walls.push( new Bitmap(m_bmd));
				m_walls[i].y = m_bmd.height * i - 100;
				addChild(m_walls[i]);
			}
			m_bm= m_walls[1];
		}
		
		private function sortByY(a:Bitmap, b:Bitmap):Number
		{ 
			return a.y>b.y?1:-1;
		}
	}
}